<template>
  <div class="mod-user">
    <el-form :inline="true" :model="dataForm" @keyup.enter.native="getDataList()">
      <el-form-item>
        <el-input v-model="dataForm.keywords" placeholder="账号" clearable style="width:200px"></el-input>
      </el-form-item>
      <el-form-item label="会员类型">
		<el-select v-model="dataForm.userType" placeholder="会员类型">
		  <el-option label="全部" value="" ></el-option>
          <el-option label="运营商" value="1" ></el-option>
		  <el-option label="普通联盟店" value="2" ></el-option>
          <el-option label="消费者" value="3" ></el-option>
          <el-option label="vip会员" value="4" ></el-option>
		  <el-option label="中级版联盟店" value="5" ></el-option>
          <el-option label="高级版联盟店" value="6" ></el-option>
          <el-option label="城市合伙人" value="7" ></el-option>
		  <el-option label="城市合伙人联盟店" value="8" ></el-option>
		</el-select>
	  </el-form-item>
      <el-form-item>
        <el-button @click="getDataList()" type="primary" plain>查询</el-button>
      </el-form-item>
    </el-form>
    <el-table
      :data="dataList"
      border
      v-loading="dataListLoading"
      @selection-change="selectionChangeHandle"
      style="width: 100%;">
      <!-- <el-table-column
        type="selection"
        header-align="center"
        align="center"
        width="50">
      </el-table-column> -->
      <el-table-column
        prop="userName"
        header-align="center"
        align="center"
        label="会员账号">
      </el-table-column>
      <el-table-column
        prop="trueName"
        header-align="center"
        align="center"
        label="会员名称">
      </el-table-column>
      <el-table-column
        prop="userType"
        header-align="center"
        align="center"
        label="会员类型">
        <template slot-scope="scope">
            <p v-if="scope.row.userType == 1"> 区域运营商</p>
            <p v-else-if ="scope.row.userType == 2">普通联盟店</p>
            <p v-else-if ="scope.row.userType == 3">消费者</p>
            <p v-else-if ="scope.row.userType == 4">VIP会员</p>
            <p v-else-if ="scope.row.userType == 5">中级版联盟店</p>
            <p v-else-if ="scope.row.userType == 6">高级版联盟店</p>
            <p v-else-if ="scope.row.userType == 7">城市合伙人</p>
            <p v-else-if ="scope.row.userType == 8">城市合伙人联盟店</p>
          </template>
      </el-table-column>
      <el-table-column
        prop="lowerUserName"
        header-align="center"
        align="center"
        label="下级会员账号">
      </el-table-column>
      <el-table-column
        prop="lowerTrueName"
        header-align="center"
        align="center"
        label="下级会员名称">
      </el-table-column>
      <el-table-column
        prop="lowerUserType"
        header-align="center"
        align="center"
        label="下级会员类型">
        <template slot-scope="scope">
            <p v-if="scope.row.lowerUserType == 1"> 区域运营商</p>
            <p v-else-if ="scope.row.lowerUserType == 2">普通联盟店</p>
            <p v-else-if ="scope.row.lowerUserType == 3">消费者</p>
            <p v-else-if ="scope.row.lowerUserType == 4">VIP会员</p>
            <p v-else-if ="scope.row.lowerUserType == 5">中级版联盟店</p>
            <p v-else-if ="scope.row.lowerUserType == 6">高级版联盟店</p>
            <p v-else-if ="scope.row.lowerUserType == 7">城市合伙人</p>
            <p v-else-if ="scope.row.lowerUserType == 8">城市合伙人联盟店</p>
          </template>
      </el-table-column>
    </el-table>
    <el-pagination
      @size-change="sizeChangeHandle"
      @current-change="currentChangeHandle"
      :current-page="pageIndex"
      :page-sizes="[10, 20, 50, 100]"
      :page-size="pageSize"
      :total="totalPage"
      layout="total, sizes, prev, pager, next, jumper">
    </el-pagination>
  </div>
</template>

<script>
export default {
  data () {
    return {
      dataForm: {
        keywords: '',
        userType: ''
      },
      dataList: [],
      pageIndex: 1,
      pageSize: 10,
      totalPage: 0,
      dataListSelections: [],
      dataListLoading: false
    }
  },
  activated () {
    this.getDataList()
  },
  methods: {
    // 获取数据列表
    getDataList () {
      this.dataListLoading = true
      this.$http({
        url: this.$http.adornUrl('/member/user/queryMembership'),
        method: 'get',
        params: this.$http.adornParams({
          'page': this.pageIndex,
          'limit': this.pageSize,
          'keywords': this.dataForm.keywords,
          'userType': this.dataForm.userType
        })
      }).then(({data}) => {
        if (data && data.code === 0) {
          this.dataList = data.data.list
          this.totalPage = data.data.totalCount
        } else {
          this.dataList = []
          this.totalPage = 0
        }
        this.dataListLoading = false
      })
    },
    // 每页数
    sizeChangeHandle (val) {
      this.pageSize = val
      this.pageIndex = 1
      this.getDataList()
    },
    // 当前页
    currentChangeHandle (val) {
      this.pageIndex = val
      this.getDataList()
    },
    // 多选
    selectionChangeHandle (val) {
      this.dataListSelections = val
    },
    // 新增 / 修改
    addOrUpdateHandle (id) {
      this.addOrUpdateVisible = true
      this.$nextTick(() => {
        this.$refs.addOrUpdate.init(id)
      })
    }
  }
}
</script>
